
#include "stdafx.h"
#include "tplaycontrolbar.h"
#include "ttoolbutton.h"
#include "tplayer.h"
#include "tplayerview.h"
#include "../core/include/core_itf.h"
#include "../core/include/tevent.h"

TPlayer::TPlayer(QWidget *parent )
	:_base(parent)
	,m_pAppCore(NULL)
{
   m_view = new TPlayerView(this);
	setCentralWidget(m_view);

	m_controlbar = new TPlayControlBar(this);
	setFootWidget(m_controlbar);
}

TPlayer::~TPlayer()
{
	if(m_pAppCore)
	{
		m_pAppCore->Destroy();
	}
	if(m_coreLibrary.isLoaded())
	{
		m_coreLibrary.unload();
	}
}

void TPlayer::Initialize()
{
	loadCore();
	if(m_pAppCore)
	{
		m_pAppCore->SetDisplayWindow((HWND)m_view->winId());
	}
}

void TPlayer::loadCore()
{
#ifdef T_DEBUG
	m_coreLibrary.setFileName("cored.dll");
#else
	m_coreLibrary.setFileName("core.dll");
#endif
	if (m_coreLibrary.load())
	{
		typedef  HRESULT (*CreateAppCoreFuc)(IAppCore **);
		CreateAppCoreFuc pCreateCore = (CreateAppCoreFuc) m_coreLibrary.resolve("CreateAppCore");
		if (pCreateCore)
		{
			pCreateCore(&m_pAppCore);
		}
	}
}
